package com.muyu.payment.service.impl;

import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.muyu.common.core.web.page.PageQueryModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.muyu.payment.mapper.PaymentConfigsMapper;
import com.muyu.payment.domain.PaymentConfigs;
import com.muyu.payment.domain.model.PaymentConfigsQueryModel;
import com.muyu.payment.domain.model.PaymentConfigsPageQueryModel;
import com.muyu.payment.domain.model.PaymentConfigsSaveModel;
import com.muyu.payment.domain.model.PaymentConfigsEditModel;
import com.muyu.payment.service.PaymentConfigsService;

/**
 * 支付配置Service业务层处理
 *
 * @author muyu
 * @date 2025-09-17
 */
@Slf4j
@Service
public class PaymentConfigsServiceImpl extends ServiceImpl<PaymentConfigsMapper, PaymentConfigs>  implements PaymentConfigsService {

    /**
     * 查询支付配置列表
     *
     * @param pageQueryModel 支付配置
     * @return 支付配置
     */
    @Override
    public PageQueryModel<PaymentConfigsPageQueryModel> pageQuery(PaymentConfigsQueryModel pageQueryModel) {
        LambdaQueryWrapper<PaymentConfigs> queryWrapper = new LambdaQueryWrapper<>();
       queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getPayType()), PaymentConfigs::getPayType, pageQueryModel.getPayType());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getAppId()), PaymentConfigs::getAppId, pageQueryModel.getAppId());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getMerchantId()), PaymentConfigs::getMerchantId, pageQueryModel.getMerchantId());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getPrivateKey()), PaymentConfigs::getPrivateKey, pageQueryModel.getPrivateKey());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getPublicKey()), PaymentConfigs::getPublicKey, pageQueryModel.getPublicKey());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getCallbackUrl()), PaymentConfigs::getCallbackUrl, pageQueryModel.getCallbackUrl());
         queryWrapper.like(ObjectUtil.isNotNull(pageQueryModel.getConfigName()),PaymentConfigs::getConfigName, pageQueryModel.getConfigName());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getIsSandbox()), PaymentConfigs::getIsSandbox, pageQueryModel.getIsSandbox());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getStatus()), PaymentConfigs::getStatus, pageQueryModel.getStatus());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getCreateTime()), PaymentConfigs::getCreateTime, pageQueryModel.getCreateTime());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getUpdateTime()), PaymentConfigs::getUpdateTime, pageQueryModel.getUpdateTime());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getCreateBy()), PaymentConfigs::getCreateBy, pageQueryModel.getCreateBy());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getUpdateBy()), PaymentConfigs::getUpdateBy, pageQueryModel.getUpdateBy());
    Page<PaymentConfigs> page = this.page(pageQueryModel.buildPage(), queryWrapper);
        return PageQueryModel.of(page).cover(PaymentConfigsPageQueryModel::infoBuild);
    }


    /**
     * 查询支付配置列表
     *
     * @param pageQueryModel 支付配置
     * @return 支付配置
     */
    @Override
    public List<PaymentConfigs> exportList(PaymentConfigs pageQueryModel) {
        LambdaQueryWrapper<PaymentConfigs> queryWrapper = new LambdaQueryWrapper<>();
       queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getPayType()), PaymentConfigs::getPayType, pageQueryModel.getPayType());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getAppId()), PaymentConfigs::getAppId, pageQueryModel.getAppId());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getMerchantId()), PaymentConfigs::getMerchantId, pageQueryModel.getMerchantId());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getPrivateKey()), PaymentConfigs::getPrivateKey, pageQueryModel.getPrivateKey());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getPublicKey()), PaymentConfigs::getPublicKey, pageQueryModel.getPublicKey());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getCallbackUrl()), PaymentConfigs::getCallbackUrl, pageQueryModel.getCallbackUrl());
         queryWrapper.like(ObjectUtil.isNotNull(pageQueryModel.getConfigName()),PaymentConfigs::getConfigName, pageQueryModel.getConfigName());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getIsSandbox()), PaymentConfigs::getIsSandbox, pageQueryModel.getIsSandbox());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getStatus()), PaymentConfigs::getStatus, pageQueryModel.getStatus());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getCreateTime()), PaymentConfigs::getCreateTime, pageQueryModel.getCreateTime());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getUpdateTime()), PaymentConfigs::getUpdateTime, pageQueryModel.getUpdateTime());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getCreateBy()), PaymentConfigs::getCreateBy, pageQueryModel.getCreateBy());
        queryWrapper.eq(ObjectUtil.isNotNull(pageQueryModel.getUpdateBy()), PaymentConfigs::getUpdateBy, pageQueryModel.getUpdateBy());
    return this.list(queryWrapper);
    }

    /**
     * 支付配置添加
     *
     * @param saveModel 支付配置
     * @return 支付配置集合
     */
    @Override
    public void save(PaymentConfigsSaveModel saveModel){
        this.save(PaymentConfigs.saveModelBuild(saveModel));
    }

    /**
     * 支付配置修改
     *
     * @param editModel 支付配置修改模型
     * @return 支付配置集合
     */
    @Override
    public void edit(PaymentConfigsEditModel editModel){
        this.updateById(PaymentConfigs.editModelBuild(editModel));
    }
}
